package com.fndsoft.police.xuancheng.ui.main;

import android.app.FragmentTransaction;
import android.widget.FrameLayout;

import com.fndsoft.police.xuancheng.R;
import com.fndsoft.police.xuancheng.domain.ThreadMessage;
import com.fndsoft.police.xuancheng.net.OperateCode;
import com.fndsoft.police.xuancheng.ui.base.BaseAc;
import com.fndsoft.police.xuancheng.ui.person.PersonFg;
import com.fndsoft.police.xuancheng.util.ViewUtil;
import com.fndsoft.police.xuancheng.view.ToolTabBar;
import com.fndsoft.police.xuancheng.view.ToolTabBar.ToolTabBarListener;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

/**
 * 主页
 * 
 * @author LiangXiangJu
 * @creationTime 2014-7-31 下午3:43:27
 * @version
 */
public class MainAc extends BaseAc {
	@ViewInject(R.id.toolTabBar)
	private ToolTabBar toolTabBar;
	@ViewInject(R.id.flPerson)
	private FrameLayout flPerson;
	@ViewInject(R.id.flVehicle)
	private FrameLayout flVehicle;
	@ViewInject(R.id.flCargo)
	private FrameLayout flCargo;
	@ViewInject(R.id.flNotice)
	private FrameLayout flNotice;

	@Override
	public void doResponseFinished(OperateCode operateCode,
			ThreadMessage threadMessage) {

	}

	@Override
	protected void installViews() {
		setContentView(R.layout.main_ac);
		ViewUtils.inject(this);

		toolTabBar.initTitles(R.array.main_tab_titles);
		toolTabBar.setToolTabBarListener(new ToolTabBarListener() {

			@Override
			public void onSeletedIndex(int index) {
				changeShowView(index);
			}
		});

		FragmentTransaction transaction = getFragmentManager()
				.beginTransaction();
		transaction.replace(R.id.flPerson, new PersonFg());
		transaction.replace(R.id.flVehicle, new PersonFg());
		transaction.replace(R.id.flCargo, new PersonFg());
		transaction.replace(R.id.flNotice, new PersonFg());
		transaction.commit();
		changeShowView(0);
	}

	/**
	 * 更换fragement显示
	 * 
	 * @author LiangXiangJu
	 * @creationTime 2014-7-31 下午3:02:15
	 * @version
	 * @param selectedIndex
	 */
	private void changeShowView(int selectedIndex) {
		ViewUtil.setViewsGone(flPerson, flVehicle, flCargo, flNotice);
		switch (selectedIndex) {
		case 0:
			ViewUtil.setViewsVisible(flPerson);
			break;
		case 1:
			ViewUtil.setViewsVisible(flVehicle);
			break;
		case 2:
			ViewUtil.setViewsVisible(flCargo);
			break;
		case 3:
			ViewUtil.setViewsVisible(flNotice);
			break;
		default:
			break;
		}
	}

	@Override
	protected void initData() {
	}

	@Override
	public boolean isCustomBackBtnEvent() {
		return false;
	}

}
